package com.azkj.album.presenter;

import com.azkj.album.dto.HistoryBean;
import com.azkj.album.dto.VipCardBean;
import com.azkj.album.dto.VipInfoBean;
import com.azkj.album.network.NetworkMaster;
import com.azkj.album.network.callback.ServiceCallback;
import com.azkj.album.network.networkframe.bean.BaseResp;
import com.azkj.album.network.networkframe.net.exception.ApiException;
import com.azkj.album.view.base.BasePresenter;
import com.azkj.album.view.iview.IVipView;
import com.azkj.album.view.widgets.dialog.DialogHelper;

import java.util.List;

public class GetVIPInfoPresenter extends BasePresenter {

    private final IVipView iVipView;


    public GetVIPInfoPresenter(IVipView iVipView) {
        this.iVipView = iVipView;
    }

    public void getVip() {
        NetworkMaster.getInstance().getCommonService().getVipInfo(new ServiceCallback<BaseResp<VipInfoBean>>() {
            @Override
            public void onSuccess(BaseResp<VipInfoBean> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iVipView.VipSuccess(jsonObj.getData());
                } else {
                    iVipView.VipFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                DialogHelper.hideDialog();
                iVipView.VipFail(apiException.errorInfo.error);
            }
        });
    }

    public void getMembershipRules() {
        NetworkMaster.getInstance().getCommonService().getMembershipRules(new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iVipView.MembershipRulesSuccess(jsonObj.getData());
                } else {
                    iVipView.MembershipRulesFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                DialogHelper.hideDialog();
                iVipView.MembershipRulesFail(apiException.errorInfo.error);
            }
        });
    }

    public void getVipCard() {
        NetworkMaster.getInstance().getCommonService().getVipCard(new ServiceCallback<BaseResp<VipCardBean>>() {
            @Override
            public void onSuccess(BaseResp<VipCardBean> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iVipView.VipCardSuccess(jsonObj.getData());
                } else {
                    iVipView.VipCardFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                DialogHelper.hideDialog();
                iVipView.VipCardFail(apiException.errorInfo.error);
            }
        });
    }

    //购买记录
    public void getHistory(String page,String limit) {
        NetworkMaster.getInstance().getCommonService().getHistory(page,limit,new ServiceCallback<BaseResp<List<HistoryBean>>>() {
            @Override
            public void onSuccess(BaseResp<List<HistoryBean>> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iVipView.HistorySuccess(jsonObj.getData());
                } else {
                    iVipView.HistoryFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                DialogHelper.hideDialog();
                iVipView.HistoryFail(apiException.errorInfo.error);
            }
        });
    }
}
